trigger setmanagerforcsedu on ConsumerEducation__c (before update,before insert) {
    list<id> idl=new list<id>();
    list<consumereducation__c> csedul=new list<consumereducation__c>();
    list<user> u=new list<user>();
    list<id> uid=new list<id>();
    boolean b=false;
     for(ConsumerEducation__c ce:trigger.new){
         idl.add(ce.id);
         uid.add(ce.ownerid);
     }
         for(consumereducation__c csedu:trigger.new){
    if(system.trigger.isupdate){
        if(system.trigger.oldmap.get(csedu.id).ownerid != csedu.ownerid){
            b=true;
        }
       }else if(system.trigger.isinsert){
           b=true;
       }
    }
     
    if(b){

    u=[select id,managerid from user where id in:uid];
    }
    
    if(system.trigger.isupdate){
    for(consumereducation__c cet:trigger.new){
        if(system.trigger.oldmap.get(cet.id).ownerid != cet.ownerid){
     
                for(user ul:u){
                    if(ul.id==cet.ownerid){  
                        cet.manager__c=ul.managerid;
                }
              }  
            }
        }
    }else if(system.trigger.isinsert){
        for(consumereducation__c cet:trigger.new){
                for(user ul:u){
                    if(ul.id==cet.ownerid){
                        cet.manager__c=ul.managerid;

                }
              }  
            }
        }
 

    
     
     
    /*   if(system.trigger.isupdate){
            if(system.trigger.oldmap.get(ce.id).ownerid != ce.ownerid){
                user u=[select id,managerid from user where id=: ce.OwnerId];
                ConsumerEducation__c hl=[select id,manager__c from ConsumerEducation__c where id=:ce.id];
                    if(u.managerid<>null){
                        ConsumerEducation__c h=hl;
                        h.manager__c=u.managerid;
                        update h;
                        }
                    }
             }else if(system.trigger.isinsert){
                     user u=[select id,managerid from user where id=: ce.OwnerId];
                ConsumerEducation__c hl=[select id,manager__c from ConsumerEducation__c where id=:ce.id];
                    if(u.managerid<>null){
                        ConsumerEducation__c h=hl;
                        h.manager__c=u.managerid;
                        update h;
                        }
             }
        }*/
}